
/*
  Windows-specific subroutines

  (C) 2009 Vasiliy Chekurov
*/

#ifndef WND_H_INCLUDED
#define WND_H_INCLUDED

#ifdef _WINDOWS
#include "windows.h"
#endif

#include "defines.h"

typedef LRESULT (*WndProc)(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


class Wnd
{
public:
  Wnd();
  ~Wnd();

  bool Open(HINSTANCE hInstance,
              HINSTANCE hPrevInstance,
              LPSTR     lpCmdLine,
              int       nCmdShow);
  int Run();
  int GetState();
  void Close();

private:
  
  ATOM				MyRegisterClass(HINSTANCE hInstance);
  BOOL				InitInstance(HINSTANCE, int);
  
  // main window procedure
  static LONG WINAPI WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
  
  // sets the 'quit' state
  static void SetQuit(bool quit);
  static bool m_quit;
  
  // handle the menu commands
  static bool MenuHandler( HWND hWnd, int wmId, int wmEvent );
  
  int m_state;

protected:
  HINSTANCE hInst;	// current instance
  HWND hWnd;        // window handle
	HACCEL hAccel;    // accelerator table
  HMENU hMenu;      // main menu

};

inline
int Wnd::GetState()
{
  if ( this->m_quit ) return STATE_CLOSE;
  else return this->m_state;
}

#endif
